package mapper;

import model.Schedule;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;

public interface ScheduleMapper {

    /**
     * 根据科室和时间(当天上/下午)查询有剩余就诊量的医生排班信息
     * @param departmentId 科室编号
     * @param sign 问诊时间
     * @return 符合条件的排班信息
     */
    @Select("select * from schedule where department_id = #{param1} " +
            "and inquiry_time = date(now()) and sign=#{param2} and remaining_quantity>0")
    @Results({
            @Result(property = "users",column = "user_id",javaType = model.SysUsers.class,
            one = @One(select = "mapper.SysUsersMapper.findById",fetchType = FetchType.LAZY))
    })
    List<Schedule> findScheduleByDepartmentIdAndInquiryTime(String departmentId, int sign);
}
